﻿using System;

using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using xbmc_json_async.System;
using xbmc_json_async.Utilities;

namespace xbmc_json_async.Media
{
    public class Artists : List<Artist>
    {

        /// <summary>
        /// Loads from json object.
        /// </summary>
        /// <param name="jsonObject">The json object.</param>
        /// <returns></returns>
        public bool LoadFromJsonObject(JObject jsonObject, Boolean isMinimalLoad)
        {
            try
            {
                //
                if (jsonObject["artists"] != null)
                {
                    foreach (JObject item in (JArray)jsonObject["artists"])
                    {
                        base.Add(Artist.FromJsonObject(item, isMinimalLoad));
                    }

                    return true;
                }
                return false;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
    }
    public class Artist : xbmc_json_async.Types.Audio.Details.Artist
    {

        /// <summary>
        /// Initializes a new instance of the <see cref="Artist"/> class.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="Label">The label.</param>
        public Artist(int id, string Label)
        {
            artistid = id;
            label = Label;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Artist"/> class.
        /// </summary>
        public Artist(){}

        /// <summary>
        /// Creates an Artist from the returned Json object
        /// </summary>
        /// <param name="item">The item.</param>
        /// <returns></returns>
        public static Artist FromJsonObject(JObject item, Boolean isMinimalLoad)
        {

            var artist = new Artist();

            Injector injector = new Injector();
            var vObj = (object)artist;
            artist = (Artist)injector.FillObject(vObj, (object)item);

            return artist;
        }

        public override string ToString()
        {
            return label;
        }
    }

}